From 6ff0fbc0376479b015bb7a7b486678633b6764aa Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sat, 9 Feb 2013 06:00:22 +0000 Subject: [PATCH] Provide overloaded helpers to gbfile to make it more forgiving of QString arguments. Minor warning cleanups. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4288 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/garmin_txt.cc | 19 ++++++++++--------- gpsbabel/gbfile.cc | 10 ++++++++++ gpsbabel/gbfile.h | 3 +++ gpsbabel/geo.cc | 2 +- gpsbabel/pathaway.cc | 4 ++-- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index 23093a885..9c8ad1edc 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -56,7 +56,7 @@ static waypoint** wpt_a; static int wpt_a_ct; static grid_type grid_index; static int datum_index; -static char* datum_str; +static const char* datum_str; static int current_line; static char* date_time_format = NULL; static int precision = 3; @@ -152,17 +152,18 @@ static const char* headers[] = { /* helpers */ -static char* -get_option_val(char* option, char* def) +static const char* +get_option_val(const char* option, const char* def) { - char* c = (option != NULL) ? option : def; + const char* c = (option != NULL) ? option : def; return c; } static void init_date_and_time_format(void) { - char* f, *c; + const char* f; + const char* c; f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT); date_time_format = convert_human_date_format(f); @@ -172,7 +173,7 @@ init_date_and_time_format(void) f = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT); c = convert_human_time_format(f); date_time_format = xstrappend(date_time_format, c); - xfree(c); + xfree((void*) c); } static void @@ -468,7 +469,7 @@ print_speed(double* distance, time_t* time) { int idist; double dist = *distance; - char* unit; + const char* unit; if (!gtxt_flags.metric) { dist = METERS_TO_MILES(dist) * 1000.0; @@ -554,7 +555,7 @@ write_waypt(const waypoint* wpt) gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? wpt->shortname : ""); if (wpt_class <= gt_waypt_class_airport_ndb) { - char* temp = wpt->notes; + const char* temp = wpt->notes; if (temp == NULL) { if (wpt->description && (strcmp(wpt->description, wpt->shortname) != 0)) { temp = wpt->description; @@ -750,7 +751,7 @@ track_disp_wpt_cb(const waypoint* wpt) static void garmin_txt_wr_init(const char* fname) { - char* grid_str; + const char* grid_str; memset(>xt_flags, 0, sizeof(gtxt_flags)); diff --git a/gpsbabel/gbfile.cc b/gpsbabel/gbfile.cc index c54133640..2cbd8edbb 100644 --- a/gpsbabel/gbfile.cc +++ b/gpsbabel/gbfile.cc @@ -774,6 +774,16 @@ gbfputs(const char* s, gbfile* file) return gbfwrite(s, 1, strlen(s), file); } +// This is a depressing hack, meant to ease the pain from C strings +// to QStrings, which are consitently encoded. +int +gbfputs(const QString& s, gbfile* file) +{ + const char* qs = s.toUtf8().data(); + unsigned int l = strlen(qs); + return gbfwrite(qs, 1, l, file); +} + /* * gbfwrite: (as fwrite) */ diff --git a/gpsbabel/gbfile.h b/gpsbabel/gbfile.h index 4bb73c45e..22575cfcc 100644 --- a/gpsbabel/gbfile.h +++ b/gpsbabel/gbfile.h @@ -26,6 +26,8 @@ #include #include #include +#include + #include "defs.h" #include "cet.h" @@ -98,6 +100,7 @@ int gbvfprintf(gbfile* file, const char* format, va_list ap); int gbfprintf(gbfile* file, const char* format, ...); int gbfputc(int c, gbfile* file); int gbfputs(const char* s, gbfile* file); +int gbfputs(const QString& s, gbfile* file); int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file); int gbfflush(gbfile* file); diff --git a/gpsbabel/geo.cc b/gpsbabel/geo.cc index 7ce2bc615..c30109f70 100644 --- a/gpsbabel/geo.cc +++ b/gpsbabel/geo.cc @@ -246,7 +246,7 @@ static void geo_wr_deinit(void) { writer.writeEndDocument(); - gbfputs(ostring.toUtf8().data(),ofd); + gbfputs(ostring,ofd); gbfclose(ofd); ofd = NULL; } diff --git a/gpsbabel/pathaway.cc b/gpsbabel/pathaway.cc index 2216e6790..8ded97995 100644 --- a/gpsbabel/pathaway.cc +++ b/gpsbabel/pathaway.cc @@ -132,7 +132,7 @@ internal_debug2(const char *format, ...) */ static -char *ppdb_strcat(char *dest, const char *src, char *def, int *size) +char *ppdb_strcat(char *dest, const char *src, const char *def, int *size) { int len; char *res; @@ -212,7 +212,7 @@ char *str_pool_get(size_t size) } static -char *str_pool_getcpy(const char *src, char *def) +char *str_pool_getcpy(const char *src, const char *def) { char *res; -- 2.30.2